package org.mpremote.android.activities;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import org.mpremote.android.R;
import org.mpremote.android.activities.abstracts.MPActivity;

/**
 * Created by IntelliJ IDEA.
 * User: Gilad
 * Date: 31/08/2010
 * Time: 21:13:12
 */
public class MusicLibraryActivity extends MPActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.music_library);
        initArtists();
        initAlbums();
        initSongs();
        initWebserviceConsumer();
    }

    private void initWebserviceConsumer() {
        final String ip = getProperty(R.string.mp_properties_mp_ip);
        final String port = getProperty(R.string.mp_properties_mp_port);
        if (ip == null || port == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Please configure your mp server URL")
                    .setCancelable(false)
                    .setPositiveButton("Configure URL", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            startActivity(new Intent(MusicLibraryActivity.this, ConfigurationActivity.class));
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    }

    private void initArtists() {
        final Button configurationButton = ((Button) findViewById(R.id.artists_button));
        configurationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MusicLibraryActivity.this, ArtistsListActivity.class));
            }
        });
    }

    private void initAlbums() {
        final Button configurationButton = ((Button) findViewById(R.id.albums_button));
        configurationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MusicLibraryActivity.this, AlbumsListActivity.class));
            }
        });
    }

    private void initSongs() {
        final Button configurationButton = ((Button) findViewById(R.id.songs_button));
        configurationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast toast = Toast.makeText(getApplicationContext(), "Not yet supported", Toast.LENGTH_SHORT);
                toast.show();
            }
        });
    }
}
